//
//  ViewController.swift
//  jmwebseoApp1803
//
//  Created by YQ05 on 2018/3/30.
//  Copyright © 2018年 YQ05. All rights reserved.
//

import UIKit
import Moya
import PageMenu

class ViewController: UIViewController {
    var pageMenu : CAPSPageMenu!
    var controllers :[UIViewController] = []
    
  
    func showMenu(){
        Category.request { (cates) in
            //self.resultLabel.text = "返回成功，数量是:" +  cates!.count.description
            
            //print(cates as Any)
            self.controllers = cates!.map{
                let vc = self.storyboard?.instantiateViewController(withIdentifier: "SBID_NEWSLIST") as! NewsListController
                
                vc.title = $0.title
                vc.parentNavi = self.navigationController
                vc.id = $0.id
                return vc
            }
            
            let param :[CAPSPageMenuOption] = [
                .menuItemSeparatorWidth(4.3),
                .scrollMenuBackgroundColor(UIColor.white),
                .viewBackgroundColor(UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)),
                .bottomMenuHairlineColor(UIColor(red: 20.0/255.0, green: 20.0/255.0, blue: 20.0/255.0, alpha: 0.1)),
                .selectionIndicatorColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),
                .menuMargin(20.0),
                .menuHeight(40.0),
                .selectedMenuItemLabelColor(UIColor(red: 18.0/255.0, green: 150.0/255.0, blue: 225.0/255.0, alpha: 1.0)),
                .unselectedMenuItemLabelColor(UIColor(red: 40.0/255.0, green: 40.0/255.0, blue: 40.0/255.0, alpha: 1.0)),
                .menuItemFont(UIFont(name: "HelveticaNeue-Medium", size: 14.0)!),
                .useMenuLikeSegmentedControl(false),
                .menuItemSeparatorRoundEdges(true),
                .selectionIndicatorHeight(2.0),
                .menuItemSeparatorPercentageHeight(0.1)
            ]
            
            let frame = CGRect(x: 0, y: 25 + 54, width: self.view.frame.width, height: self.view.frame.height - 25 - 54)
            // Initialize page menu with controller array, frame, and optional parameters
            self.pageMenu = CAPSPageMenu(viewControllers: self.controllers, frame: frame, pageMenuOptions: param)
            
            // Lastly add page menu as subview of base view controller view
            // or use pageMenu controller in you view hierachy as desired
            self.view.addSubview(self.pageMenu.view)
        }
    }

//    @IBOutlet weak var ptitle: UILabel!
//    @IBAction func showlist2Btn(_ sender: UIButton) {
//        print("2点击了")
//        //getprocateList(id: 11)
//
//        Posts.request(id: 11) { (posts) in
//            let proarr = posts?.count.description
//
//
//
//            self.ptitle.text = "返回的数据结果" + proarr!
//
//            print(posts)
//
//        }
//    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)
        
        showMenu()
        //getprocateList(id: 11)
    }

}

